﻿/**
 * 信计团队
 * @version 1.0
 * 网址：http://www.huas.cn
 * E-mail：xieqingcheng@126.com ; txws1010@163.com
 * Copyright 2011 Hunan University of Arts and Science
 */
package cn.huas.action;

/**
 * 排课相关
 * Aug 02,2011
 */

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.huas.dao.service.RecordManager;
import cn.huas.model.Admin;
import cn.huas.model.Classes;
import cn.huas.model.Classroom;
import cn.huas.model.Course;
import cn.huas.model.CourseRClass;
import cn.huas.model.Professional;
import cn.huas.model.Systems;
import cn.huas.model.Teachers;
import cn.huas.model.TeachersRCourse;
import cn.huas.model.Teachingbuilding;
import cn.huas.modelVo.ArgsFlag;
import cn.huas.modelVo.JAll;
import cn.huas.util.ActionContextUtil;
import cn.huas.util.Page;
import cn.huas.util.User;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("unchecked")
public class RecordAction extends ActionSupport {

	/** 
	 *  
	 */
	private static final long serialVersionUID = -1963993443719819809L;
	private Admin admin;
	private ArgsFlag argsFlag;
	private Classes classes;
	private Classroom classroom;
	private String flag;
	private String ids;
	private Integer limit;
	private Page page;
	private Professional professional;
	@Resource
	private RecordManager recordManager;
	private Integer start;
	private Systems systems;
    private Teachers teachers;
	private TeachersRCourse teachersRcourse;
	private Teachingbuilding teachingbuilding;
	private User user;
	private String teachers_ids;
	public String getTeachers_ids() {
		return teachers_ids;
	}
	public void setTeachers_ids(String teachersIds) {
		teachers_ids = teachersIds;
	}
	public String getClasses_ids() {
		return classes_ids;
	}
	public void setClasses_ids(String classesIds) {
		classes_ids = classesIds;
	}

	private String classes_ids;
	private String course_ids;
	public String getCourse_ids() {
		return course_ids;
	}
	public void setCourse_ids(String courseIds) {
		course_ids = courseIds;
	}

	public Course getCourse() {
		return course;
	}
	public void setCourse(Course course) {
		this.course = course;
	}

	private Course course;

	public String addToTeachersRCourse() {
		boolean flag=false;
		@SuppressWarnings("unused")
		HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response = ActionContextUtil
				.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		try{
				flag= recordManager.addToTeachersRCourse(course_ids,teachers_ids);
		if (flag) {
			response.getWriter().print("{success:true,msg:'保存成功'}");
			return null;
		} else {
			// 添加错误的提示信息
			response.getWriter().print("{success:false,msg:'保存失败'}");
			return null;
		}}catch (Exception e) {
			try {
				response.getWriter().print(
						"{success:false,msg:'" + e.getMessage() + "'}");
				e.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			return null;
		}
	}
	
	public String delFromCourseRClass() {
		try {
			boolean flag = recordManager.delFromCourseRClass(classes_ids,course_ids);
			@SuppressWarnings("unused")
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if (flag) {
				response.getWriter().print("{success:true'}");
				return null;
			} else {
				response.getWriter().print("{success:false'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	
	}
	public String addToCourseRClass() {
		boolean flag=false;
		@SuppressWarnings("unused")
		HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response = ActionContextUtil
				.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		try{
				flag= recordManager.addToCourseRClass(course_ids,classes_ids);
		if (flag) {
			response.getWriter().print("{success:true,msg:'保存成功'}");
			return null;
		} else {
			// 添加错误的提示信息
			response.getWriter().print("{success:false,msg:'保存失败'}");
			return null;
		}}catch (Exception e) {
			try {
				response.getWriter().print(
						"{success:false,msg:'" + e.getMessage() + "'}");
				e.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			return null;
		}
	}
	
	public List<TeachersRCourse> queryTeachersRCourse(ArgsFlag args){
		List<TeachersRCourse> list = new ArrayList<TeachersRCourse>();
		try{
			list = recordManager.queryTeachersRCourse(args);
			return list;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	public String addAdmin() {
		@SuppressWarnings("unused")
		HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response = ActionContextUtil
				.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		boolean flag = true;
		try {
			ArgsFlag args = new ArgsFlag();
			if (admin.getAdmin_id() != null) {
				args.setFlag01(admin.getAdmin_id());
			}
			args.setFlag10(admin.getAdmin_name());
			args.setFlag01(admin.getAdmin_id());
			List<Admin> list1 = recordManager.queryAdmin(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getAdmin_name().equals(
							admin.getAdmin_name())) {
						response.getWriter().print(
								"{success:false,msg:'失败，用户名已存在！！'}");
						return null;
					}
				}
			flag = recordManager.addAdmin(admin);
			if (flag) {
				response.getWriter().print("{success:true,msg:'保存成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'保存失败'}");
				return null;
			}
		} catch (Exception e) {
			try {
				response.getWriter().print(
						"{success:false,msg:'" + e.getMessage() + "'}");
				e.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
			return null;
		}
	}
	public String addClasses() {
		boolean flag = true;
		@SuppressWarnings("unused")
		HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response = ActionContextUtil
				.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		try {
			ArgsFlag args = new ArgsFlag();
			if (classes.getClasses_id() != null) {
				args.setFlag01(classes.getClasses_id());
			}
			args.setFlag10(classes.getClasses_name());
			List<Classes> list1 = recordManager.queryClasses(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getClasses_name().equals(classes.getClasses_name())) {
								response
										.getWriter()
										.print(
												"{success:false,msg:'失败，不能有同名的班级'}");
								return null;
						}

				}
			flag = recordManager.addClasses(classes);
			if (flag) {
				response.getWriter().print("{success:true,msg:'保存成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'保存失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	public String addClassroom() {
		boolean flag = true;
		@SuppressWarnings("unused")
		HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response = ActionContextUtil
				.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		try {
			ArgsFlag args = new ArgsFlag();
			ArgsFlag args1 = new ArgsFlag();
			if (classroom.getId() != null) {
				args.setFlag01(classroom.getId());
				args1.setFlag01(classroom.getTeachingbuilding()
						.getTeachingbuilding_id());
			}
			args.setFlag10(classroom.getName());
			args1.setFlag00(classroom.getTeachingbuilding()
					.getTeachingbuilding_id());
			List<Classroom> list1 = recordManager.queryClassroom(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getName().equals(classroom.getName())) {
						List<Teachingbuilding> teacherbuilding = recordManager
								.queryTeachingbuilding(args1);
						for (int j = 0; i < teacherbuilding.size(); i++) {
							if (teacherbuilding.get(j).getTeachingbuilding_id()
									.equals(
											classroom.getTeachingbuilding()
													.getTeachingbuilding_id())) {
								response
										.getWriter()
										.print(
												"{success:false,msg:'失败，同一个教学楼不能有同名的教室'}");
								return null;
							}
						}

					}
				}
			flag = recordManager.addClassroom(classroom);
			if (flag) {
				response.getWriter().print("{success:true,msg:'保存成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'保存失败'}");
				return null;
			}
		} catch (Exception e) {
			try {
				response.getWriter().print(
						"{success:false,msg:'" + e.getMessage() + "'}");
				e.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			return null;
		}
	}
	public String addProfessional() {
		@SuppressWarnings("unused")
		HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response = ActionContextUtil
				.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		boolean flag = true;
		try {
			ArgsFlag args = new ArgsFlag();
			if (professional.getProfessional_id() != null) {
				args.setFlag01(professional.getProfessional_id());
			}
			args.setFlag10(professional.getProfessional_name());
			List<Professional> list1 = recordManager.queryProfessional(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getProfessional_name().equals(
							professional.getProfessional_name())) {
						response.getWriter().print(
								"{success:false,msg:'失败，专业名称不能同名！！'}");
						return null;
					}
				}
			flag = recordManager.addProfessional(professional);
			if (flag) {
				response.getWriter().print("{success:true,msg:'保存成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'保存失败'}");
				return null;
			}
		} catch (Exception e) {
			try {
				response.getWriter().print(
						"{success:false,msg:'" + e.getMessage() + "'}");
				e.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
			return null;
		}
	}
	public String addSystems() {
		@SuppressWarnings("unused")
		HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response = ActionContextUtil
				.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		boolean flag = true;
		try {
			ArgsFlag args = new ArgsFlag();
			if (args.getFlag01() != null) {
				args.setFlag01(systems.getSystems_id());
			}
			args.setFlag10(systems.getSystems_name());
			List<Systems> list1 = recordManager.querySystems(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getSystems_name().equals(
							systems.getSystems_name())) {
						response.getWriter().print(
								"{success:false,msg:'失败，院系名称不能同名！！'}");
						return null;
					}
				}
			flag = recordManager.addSystems(systems);
			if (flag) {
				response.getWriter().print("{success:true,msg:'保存成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'保存失败'}");
				return null;
			}
		} catch (Exception e) {
			try {
				response.getWriter().print(
						"{success:false,msg:'" + e.getMessage() + "'}");
				e.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
			return null;
		}
	}
	public String addTeachers() {
		@SuppressWarnings("unused")
		HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response = ActionContextUtil
				.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		boolean flag = true;
		try {
			ArgsFlag args = new ArgsFlag();
			if (teachers.getTeachers_id() != null) {
				args.setFlag01(teachers.getTeachers_id());
			}
			args.setFlag10(teachers.getTeachers_name());
			List<Teachers> list1 = recordManager.queryTeachers(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getTeachers_name().equals(
							teachers.getTeachers_name())) {
						response.getWriter().print(
								"{success:false,msg:'失败，该老师已经存在！！'}");
						return null;
					}
				}
			flag = recordManager.addTeachers(teachers);
			if (flag) {
				response.getWriter().print("{success:true,msg:'保存成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'保存失败'}");
				return null;
			}
		} catch (Exception e) {
			try {
				response.getWriter().print(
						"{success:false,msg:'" + e.getMessage() + "'}");
				e.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
			return null;
		}
	}
/*
	public String addTeachersRCourse() {
		boolean flag = true;
		@SuppressWarnings("unused")
		HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response = ActionContextUtil
				.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		try {
			ArgsFlag args = new ArgsFlag();
			if (teachersRcourse.getCourse().getCourse_id() != null) {
				args.setFlag03(teachersRcourse.getCourse().getCourse_id());
			}
			args.setFlag10(teachersRcourse.getCourse().getCourse_name());
			List<TeachersRCourse> list1 = recordManager
					.queryTeachersRCourse(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getCourse().getCourse_name().equals(
							teachersRcourse.getCourse().getCourse_name())) {
						response.getWriter().print(
								"{success:false,msg:'失败，该课程已存在！！'}");
						return null;
					}
				}
			flag = recordManager.addTeachersRCourse(teachersRcourse);
			if (flag) {
				response.getWriter().print("{success:true,msg:'保存成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'保存失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	
	*/
	public String addCourse() {
		boolean flag = true;
		@SuppressWarnings("unused")
		HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response = ActionContextUtil
				.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		try {
			ArgsFlag args = new ArgsFlag();
			if (course.getCourse_id() != null) {
				args.setFlag03(course.getCourse_id());
			}
			args.setFlag10(course.getCourse_name());
			List<Course> list1 = recordManager
					.queryCourse(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getCourse_name().equals(
							course.getCourse_name())) {
						response.getWriter().print(
								"{success:false,msg:'失败，该课程已存在！！'}");
						return null;
					}
				}
			flag = recordManager.addCourse(course);
			if (flag) {
				response.getWriter().print("{success:true,msg:'保存成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'保存失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	public String deleteCourse() {
		try {
			boolean flag = this.recordManager.deleteCourse(ids);
			@SuppressWarnings("unused")
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if (flag) {
				response.getWriter().print("{success:true,msg:'删除成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'删除失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}

	}
	
	/**
	 * 
	 name : "flag0", fieldLabel : "课程名称", name : "flag1", fieldLabel : "任课老师",
	 * name : "flag2", fieldLabel : "课程类型",
	 * 
	 * @return
	 */
	public String queryCourse() {
		try {
			if (flag != null) {
				flag = URLDecoder.decode(flag, "UTF-8");
				if (!"undefined".equals(flag)) {
					String[] params = flag.split(",");
					if ("-".equals(params[0])) {
						params[0] = "";
					}
					if ("-".equals(params[1])) {
						params[1] = "";
					}
					if ("-".equals(params[2])) {
						params[2] = "";
					}
					argsFlag = new ArgsFlag();
					argsFlag.setFlag10(params[0]);
					argsFlag.setFlag11(params[1]);
					argsFlag.setFlag12(params[2]);
				}
			}
			List<Course> list = recordManager.queryCourse(argsFlag);
			int size=list.size();
			if(start!=null||limit!=null){
				  int length;	
				  if(start+limit>list.size()-1)   length=list.size()-1;
				  else{
					  length=start+limit-1;
				  }
				  List<Course> list1=new ArrayList<Course>();
					for(int i=start;i<=length;i++)
					{
						list1.add(list.get(i));
					 }
					list=list1;
			}
			page.setRoot(list);
			page.setTotalProperty(size);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String delFromTeachersRCourse() {
		try {
			boolean flag = recordManager.delFromTeachersRCourse(teachers_ids,course_ids);
			@SuppressWarnings("unused")
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if (flag) {
				response.getWriter().print("{success:true,msg:'删除成功'}");
				return null;
			} else {
				response.getWriter().print("{success:false,msg:'删除失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}

	}
	public String addTeachingbuilding() {
		@SuppressWarnings("unused")
		HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response = ActionContextUtil
				.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		boolean flag = true;
		try {
			ArgsFlag args = new ArgsFlag();
			if (teachingbuilding.getTeachingbuilding_id() != null) {
				args.setFlag01(teachingbuilding.getTeachingbuilding_id());
			}
			args.setFlag10(teachingbuilding.getTeachingbuilding_name());
			List<Teachingbuilding> list1 = recordManager
					.queryTeachingbuilding(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getTeachingbuilding_name().equals(
							teachingbuilding.getTeachingbuilding_name())) {
						response.getWriter().print(
								"{success:false,msg:'失败，教学楼名称不能同名！！'}");
						return null;
					}
				}
			flag = recordManager.addTeachingbuilding(teachingbuilding);
			if (flag) {
				response.getWriter().print("{success:true,msg:'保存成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'保存失败'}");
				return null;
			}
		} catch (Exception e) {
			try {
				response.getWriter().print(
						"{success:false,msg:'" + e.getMessage() + "'}");
				e.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
			return null;
		}
	}

	public String deleteAdmin() {
		try {
			boolean flag = recordManager.deleteAdmin(ids);
			@SuppressWarnings("unused")
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if (flag) {
				response.getWriter().print("{success:true,msg:'删除成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'删除失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}

	}

	public String deleteClasses() {
		try {
			boolean flag = this.recordManager.deleteClasses(ids);

			@SuppressWarnings("unused")
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if (flag) {
				response.getWriter().print("{success:true,msg:'删除成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'删除失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}

	}

	public String deleteClassroom() {
		try {
			Boolean flag = recordManager.deleteClassroom(ids);
			@SuppressWarnings("unused")
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if (flag) {
				response.getWriter().print("{success:true,msg:'删除成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'删除失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public String deleteProfessional() {
		try {
			boolean flag = recordManager.deleteProfessional(ids);
			@SuppressWarnings("unused")
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if (flag) {
				response.getWriter().print("{success:true,msg:'删除成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'删除失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}

	}

	public String deleteSystems() {
		try {
			boolean flag = recordManager.deleteSystems(ids);
			@SuppressWarnings("unused")
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if (flag) {
				response.getWriter().print("{success:true,msg:'删除成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'删除失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}

	}

	public String deleteTeachers() {
		try {
			boolean flag = this.recordManager.deleteTeachers(ids);

			@SuppressWarnings("unused")
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if (flag) {
				response.getWriter().print("{success:true,msg:'删除成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'删除失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}

	}

	

	public String deleteTeachingbuilding() {
		try {
			boolean flag = recordManager.deleteTeachingbuilding(ids);
			@SuppressWarnings("unused")
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if (flag) {
				response.getWriter().print("{success:true,msg:'删除成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'删除失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}

	}

	public Admin getAdmin() {
		return admin;
	}

	public ArgsFlag getArgsFlag() {
		return argsFlag;
	}

	public Classes getClasses() {
		return classes;
	}

	public Classroom getClassroom() {
		return classroom;
	}

	public String getFlag() {
		return flag;
	}

	public String getIds() {
		return ids;
	}

	public Integer getLimit() {
		return limit;
	}

	public Page getPage() {
		return page;
	}

	public Professional getProfessional() {
		return professional;
	}

	public RecordManager getRecordManager() {
		return recordManager;
	}

	public Integer getStart() {
		return start;
	}

	public Systems getSystems() {
		return systems;
	}

	public Teachers getTeachers() {
		return teachers;
	}

	public TeachersRCourse getTeachersRcourse() {
		return teachersRcourse;
	}

	public Teachingbuilding getTeachingbuilding() {
		return teachingbuilding;
	}

	public User getUser() {
		return user;
	}

	

	/**
	 * name : "flag0", fieldLabel : "用户姓名",
	 * 
	 * @return
	 */
	public String queryAdmin() {
		try {
			if (flag != null) {
				flag = URLDecoder.decode(flag, "UTF-8");
				if (!"undefined".equals(flag)) {
					if ("-".equals(flag)) {
						flag = "";
					}
					argsFlag = new ArgsFlag();
					argsFlag.setFlag10(flag);
				}
			}
			List<Admin> list = recordManager.queryAdmin(argsFlag);
			int size=list.size();
			if(start!=null||limit!=null){
				  int length;	
				  if(start+limit>size-1)   length=list.size()-1;
				  else{
					  length=start+limit-1;
				  }
				  List<Admin> list1=new ArrayList<Admin>();
					for(int i=start;i<=length;i++)
					{
						list1.add(list.get(i));
					 }
					list=list1;
				}
			page.setRoot(list);
			page.setTotalProperty(size);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/***
	 * name : "flag2", fieldLabel : "所属院系", name : "flag0", fieldLabel : "班级编号",
	 * name : "flag3", fieldLabel : "所属专业", name : "flag1", fieldLabel : "班级名称",
	 * 
	 * @return
	 */
	public String queryClasses() {
		argsFlag = new ArgsFlag();
		try {
			if (flag != null) {
				flag = URLDecoder.decode(flag, "UTF-8");
				if (!"undefined".equals(flag)) {
					if (!flag.contains(",")) {
						argsFlag.setFlag03(Integer.parseInt(flag));
					} else {
						String[] params = flag.split(",");
						if ("-".equals(params[0])) {// 班级编号
							params[0] = "";
						}
						if ("-".equals(params[1])) {// 班级名称
							params[1] = "";
						}
						if ("-".equals(params[2])) {// 所属院系ID
							params[2] = "";
						}
						if ("-".equals(params[3])) {// 所属专业ID
							params[3] = "";
						}
						// 班级编号查询暂时未涉及
						// argsFlag.setFlag4(params[0]);
						argsFlag.setFlag10(params[1]);
						if(params[2]!=""||params[2]!=null){
							argsFlag.setFlag02(Integer.parseInt(params[2]));
						}
						if(params[3]!=""||params[3]!=null){
							argsFlag.setFlag03(Integer.parseInt(params[3]));
						}
					}
				}
			}
			List<Classes> list = recordManager.queryClasses(argsFlag);
			int size=list.size();
			if(start!=null||limit!=null){
				  int length;	
				  if(start+limit>list.size()-1)   length=list.size()-1;
				  else{
					  length=start+limit-1;
				  }
				  List<Classes> list1=new ArrayList<Classes>();
					for(int i=start;i<=length;i++)
					{
						list1.add(list.get(i));
					 }
					list=list1;
				}
			page.setRoot(list);
			page.setTotalProperty(size);
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}

	/***
	 * 
	 name : "flag0", fieldLabel : "教室编号", name : "flag1", fieldLabel : "教室类型",
	 */
	public String queryClassroom() {
		try {
			if (flag != null) {
				flag = URLDecoder.decode(flag, "UTF-8");
				if (!"undefined".equals(flag)) {
					String[] params = flag.split(",");
					if ("-".equals(params[0])) {// 教室名称
						params[0] = "";
					}
					if ("-".equals(params[1])) {// 教室类型
						params[1] = "";
					}
					argsFlag = new ArgsFlag();
					argsFlag.setFlag10(params[0]);
					argsFlag.setFlag11(params[1]);
				}
			}
			List<Classroom> list = recordManager.queryClassroom(argsFlag);
			int size=list.size();
			if(start!=null||limit!=null){
				  int length;	
				  if(start+limit>list.size()-1)   length=list.size()-1;
				  else{
					  length=start+limit-1;
				  }
				  List<Classroom> list1=new ArrayList<Classroom>();
					for(int i=start;i<=length;i++)
					{
						list1.add(list.get(i));
					 }
					list=list1;
				}
			page.setRoot(list);
			page.setTotalProperty(size);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/***
	 * name : "flag0", fieldLabel : "所属院系", name : "flag2", fieldLabel : "专业名称",
	 * name : "flag1", fieldLabel : "专业编号",
	 * 
	 * @return
	 */
	public String queryProfessional() {
		try {
			argsFlag = new ArgsFlag();
			if (flag != null) {
				flag = URLDecoder.decode(flag, "UTF-8");
				if (!"undefined".equals(flag)) {
					if (!flag.contains(",")) {
						argsFlag.setFlag02(Integer.parseInt(flag));
					} else {
						String[] params = flag.split(",");
						if ("-".equals(params[0])) {// 所属院系名称
							params[0] = "";
						}
						if ("-".equals(params[1])) {// 专业名称
							params[1] = "";
						}

						argsFlag.setFlag10(params[0]);
						argsFlag.setFlag11(params[1]);

					}
				}
			}
			HttpServletRequest request = ActionContextUtil.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if(!(request.getParameter("systems_id")==null||"".equals(request.getParameter("systems_id")))){
				Integer systems_id=Integer.parseInt(request.getParameter("systems_id"));
				argsFlag.setFlag02(systems_id);
			}
			List<Professional> list = recordManager.queryProfessional(argsFlag);
			int size=list.size();
			if(start!=null||limit!=null){
				  int length;	
				  if(start+limit>list.size()-1)   length=list.size()-1;
				  else{
					  length=start+limit-1;
				  }
				  List<Professional> list1=new ArrayList<Professional>();
					for(int i=start;i<=length;i++)
					{
						list1.add(list.get(i));
					 }
					list=list1;
				}
			page.setRoot(list);
			page.setTotalProperty(size);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * systems name : "flag1", fieldLabel : "院系名称", name : "flag0", fieldLabel
	 * :"院系编号",
	 */
	public String querySystems() {
		try {
			if (flag != null) {
				flag = URLDecoder.decode(flag, "UTF-8");
				if (!"undefined".equals(flag)) {
						if ("-".equals(flag)) {//院系名称
							flag= "";
					}
					argsFlag = new ArgsFlag();
					argsFlag.setFlag10(flag);
				}
			}
			List<Systems> list = recordManager.querySystems(argsFlag);
			int size=list.size();
			if(start!=null||limit!=null){
			  int length;	
			  if(start+limit>list.size()-1)   length=list.size()-1;
			  else{
				  length=start+limit-1;
			  }
			  List<Systems> list1=new ArrayList<Systems>();
				for(int i=start;i<=length;i++)
				{
					list1.add(list.get(i));
				 }
				list=list1;
			}
			page.setRoot(list);
			page.setTotalProperty(size);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * name : "flag2", fieldLabel : "所属院系", name : "flag0", fieldLabel : "教师职称",
	 * name : "flag1", fieldLabel : "教师名称",
	 * 
	 * @return
	 */
	public String queryTeachers() {
		try {
			if (flag != null) {
				flag = URLDecoder.decode(flag, "UTF-8");
				if (!"undefined".equals(flag)) {
					String[] params = flag.split(",");
					if ("-".equals(params[0])) {// 教师职称
						params[0] = "";
					}
					if ("-".equals(params[1])) {// 教师名称
						params[1] = "";
					}
					if ("-".equals(params[2])) {// 所属院系
						params[2] = "";
					}
					argsFlag = new ArgsFlag();
					argsFlag.setFlag12(params[0]);
					argsFlag.setFlag10(params[1]);
					argsFlag.setFlag11(params[2]);
				}
			}
			List<Teachers> list = recordManager.queryTeachers(argsFlag);
			int size=list.size();
			if(start!=null||limit!=null){
				  int length;	
				  if(start+limit>list.size()-1)   length=list.size()-1;
				  else{
					  length=start+limit-1;
				  }
				  List<Teachers> list1=new ArrayList<Teachers>();
					for(int i=start;i<=length;i++)
					{
						list1.add(list.get(i));
					 }
					list=list1;
			}
			page.setRoot(list);
			page.setTotalProperty(size);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * 
	 name : "flag0", fieldLabel : "课程名称", name : "flag1", fieldLabel : "任课老师",
	 * name : "flag2", fieldLabel : "课程类型",
	 * 
	 * @return
	 */
	/*
	public String queryTeachersRCourse() {
		try {
			if (flag != null) {
				flag = URLDecoder.decode(flag, "UTF-8");
				if (!"undefined".equals(flag)) {
					String[] params = flag.split(",");
					if ("-".equals(params[0])) {
						params[0] = "";
					}
					if ("-".equals(params[1])) {
						params[1] = "";
					}
					if ("-".equals(params[2])) {
						params[2] = "";
					}
					argsFlag = new ArgsFlag();
					argsFlag.setFlag10(params[0]);
					argsFlag.setFlag11(params[1]);
					argsFlag.setFlag12(params[2]);
				}
			}
			List<TeachersRCourse> list = recordManager.queryTeachersRCourse(argsFlag);
			int size=list.size();
			if(start!=null||limit!=null){
				  int length;	
				  if(start+limit>list.size()-1)   length=list.size()-1;
				  else{
					  length=start+limit-1;
				  }
				  List<TeachersRCourse> list1=new ArrayList<TeachersRCourse>();
					for(int i=start;i<=length;i++)
					{
						list1.add(list.get(i));
					 }
					list=list1;
			}
			page.setRoot(list);
			page.setTotalProperty(size);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
*/
	/***
	 * Teachingbuilding name : "flag1", fieldLabel : "教学楼名称", name :
	 * "flag0",fieldLabel : "教学楼编号", name : "flag2", fieldLabel : "所属院系",
	 * 
	 * @return
	 */
	public String queryTeachingbuilding() {
		try {
			if (flag != null) {
				flag = URLDecoder.decode(flag, "UTF-8");
				if (!"undefined".equals(flag)) {
					String[] params = flag.split(",");
					if ("-".equals(params[0])) {
						params[0] = "";
					}
					if ("-".equals(params[1])) {
						params[1] = "";
					}
					if ("-".equals(params[2])) {
						params[2] = "";
					}
					argsFlag = new ArgsFlag();
					// 暂时未涉及 argsFlag.setFlag0(params[0]);//教学楼编号
					argsFlag.setFlag10(params[1]);// 教学楼名称
					argsFlag.setFlag11(params[2]);// 所属院系名称
				}
			}
			List<Teachingbuilding> list = recordManager.queryTeachingbuilding(argsFlag);
			int size=list.size();
			if(start!=null||limit!=null){
				  int length;	
				  if(start+limit>list.size()-1)   length=list.size()-1;
				  else{
					  length=start+limit-1;
				  }
				  List<Teachingbuilding> list1=new ArrayList<Teachingbuilding>();
					for(int i=start;i<=length;i++)
					{
						list1.add(list.get(i));
					 }
					list=list1;
			}
			page.setRoot(list);
			page.setTotalProperty(size);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	public void setArgsFlag(ArgsFlag argsFlag) {
		this.argsFlag = argsFlag;
	}

	public void setClasses(Classes classes) {
		this.classes = classes;
	}

	public void setClassroom(Classroom classroom) {
		this.classroom = classroom;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public void setProfessional(Professional professional) {
		this.professional = professional;
	}

	public void setRecordManager(RecordManager recordManager) {
		this.recordManager = recordManager;
	}
	public void setStart(Integer start) {
		this.start = start;
	}
	public void setSystems(Systems systems) {
		this.systems = systems;
	}
	
	public void setTeachers(Teachers teachers) {
		this.teachers = teachers;
	}
	public void setTeachersRcourse(TeachersRCourse teachersRcourse) {
		this.teachersRcourse = teachersRcourse;
	}
	
	
	public void setTeachingbuilding(Teachingbuilding teachingbuilding) {
		this.teachingbuilding = teachingbuilding;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	// 验证码的Action
	public String userIdentifyingCode() {
		int width = 60;
		int height = 20;
		try {
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");

			BufferedImage buffImg = new BufferedImage(width, height,
					BufferedImage.TYPE_INT_RGB);
			Graphics2D g = buffImg.createGraphics();
			// 创建一个随机数生成器
			Random random = new Random();
			g.setColor(Color.ORANGE);
			g.fillRect(0, 0, width, height);
			// 字体，大小等参数
			Font font = new Font("Times New Roman", Font.PLAIN, 18);
			// 设置字体
			g.setFont(font);
			// 画边框
			g.setColor(Color.ORANGE);
			g.drawRect(0, 0, width - 1, height - 1);
			// 随机产生160条干扰线
			g.setColor(Color.ORANGE);
			for (int i = 0; i < 160; i++) {
				int x = random.nextInt(width);
				int y = random.nextInt(height);
				int x1 = random.nextInt(12);
				int y1 = random.nextInt(12);
				g.drawLine(x, y, x + x1, y + y1);
			}
			// randomCode用于保存随机产生的验证码
			StringBuffer randomCode = new StringBuffer();
			int red = 0, green = 0, blue = 0;
			// 随机产生验证码数字
			for (int i = 0; i < 4; i++) {
				String strRand = String.valueOf(random.nextInt(10));
				// 产生随机的颜色分量来构造颜色值
				red = random.nextInt(10);
				green = random.nextInt(50);
				blue = random.nextInt(50);
				// 用随机产生的颜色将验证码绘制在图像中
				g.setColor(new Color(red, green, blue));
				g.drawString(strRand, 13 * i + 6, 16);
				// 将产生的四个随机数组合在一起
				randomCode.append(strRand);
			}
			// 四位数字验证码保存在Session中
			HttpSession session = request.getSession();
			session.setAttribute("randomCode", randomCode.toString());
			// 禁止图像缓存
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "cache");
			response.setDateHeader("Exoires", 0);
			response.setContentType("unage/jpeg");
			// 将图像输出到Servlet的输出流中
			ServletOutputStream sos = response.getOutputStream();
			ImageIO.write(buffImg, "jpeg", sos);
			sos.close();
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		return null;
	}
	//----------管理员登陆-----------
	public String loginAdmin(){
		boolean flag1=false;
		boolean flag = false;
		HttpServletRequest request=ActionContextUtil.getHttpServletRequest();
		@SuppressWarnings("unused")
		HttpServletResponse response=ActionContextUtil.getHttpServletResponse();
		//获取数据库中admin对象
		
			ArgsFlag args = new ArgsFlag();
			args.setFlag10(user.getUser_name());
			List<Admin> list1;
			try {
			list1 = recordManager.queryAdmin(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getAdmin_name().equals(
							user.getUser_name())) {
						request.getSession().setAttribute("admin",list1.get(i));
						try {
							flag = recordManager.loginAdmin(list1.get(i));
						} catch (Exception e1) {
							e1.printStackTrace();
						}

					}
				}
			} catch (Exception e1) {
			e1.printStackTrace();
		}
		//判断登陆时验证码是否正确
		String c_checkcode = request.getParameter("checkcode");
		String s_checkcode = (String)request.getSession().getAttribute("randomCode");
		try{
		if(c_checkcode.equals(s_checkcode)){
			flag1 = true;
		}else{
			flag1=false;
			request.setAttribute("message", "验证码错误！");
		}
		}catch(Exception e){
			e.printStackTrace();
		}
		if(flag==true&&flag1==true){
			
			//response.getWriter().print("{success:true,msg:'登陆成功'}");
			return SUCCESS;
		
		}else{
			//response.getWriter().print("{success:false,msg:'登陆失败'}");
			
			return ERROR;
			}
		
		}

	
	//----------班级登陆-----------
	public String loginClasses(){
	
		boolean flag1=false;
		boolean flag = false;
		HttpServletRequest request=ActionContextUtil.getHttpServletRequest();
		@SuppressWarnings("unused")
		HttpServletResponse response=ActionContextUtil.getHttpServletResponse();
		//获取数据库中classes对象
		try {
			ArgsFlag args = new ArgsFlag();
			args.setFlag10(user.getUser_name());
			List<Classes> list1;
			list1 = recordManager.queryClasses(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getClasses_name().equals(
							user.getUser_name())) {
						request.getSession().setAttribute("classes",list1.get(i));
						try {
							flag = recordManager.loginClasses(list1.get(i));
						} catch (Exception e1) {
							e1.printStackTrace();
						}
					}
				}
			} catch (Exception e1) {
			e1.printStackTrace();
		}
		//判断登陆时验证码是否正确
		String c_checkcode = request.getParameter("checkcode");
		String s_checkcode = (String)request.getSession().getAttribute("randomCode");
		try{
		if(c_checkcode.equals(s_checkcode)){
			flag1 = true;
		}else{
			flag1=false;
			request.setAttribute("message", "验证码错误！");
		}
		}catch(Exception e){
			e.printStackTrace();
		}
		if(flag==true&&flag1==true){
			
			//response.getWriter().print("{success:true,msg:'登陆成功'}");
			return SUCCESS;
		
		}else{
			//response.getWriter().print("{success:false,msg:'登陆失败'}");
			
			return ERROR;
			}
		
		}
	//----------教师登陆-----------
	public String loginTeachers(){
	
		boolean flag1=false;
		boolean flag = false;
		HttpServletRequest request=ActionContextUtil.getHttpServletRequest();
		@SuppressWarnings("unused")
		HttpServletResponse response=ActionContextUtil.getHttpServletResponse();
		//获取数据库中teachers对象
		try {
			ArgsFlag args = new ArgsFlag();
			args.setFlag10(user.getUser_name());
			List<Teachers> list1;
			list1 = recordManager.queryTeachers(args);
			if (list1 != null)
				for (int i = 0; i < list1.size(); i++) {
					if (list1.get(i).getTeachers_name().equals(
							user.getUser_name())) {
						request.getSession().setAttribute("teachers",list1.get(i));
						try {
							flag = recordManager.loginTeachers(list1.get(i));
						} catch (Exception e1) {
							e1.printStackTrace();
						}

					}
				}
			} catch (Exception e1) {
			e1.printStackTrace();
		}
		//判断登陆时验证码是否正确
		String c_checkcode = request.getParameter("checkcode");
		String s_checkcode = (String)request.getSession().getAttribute("randomCode");
		try{
		if(c_checkcode.equals(s_checkcode)){
			flag1 = true;
		}else{
			flag1=false;
			request.setAttribute("message", "验证码错误！");
		}
		}catch(Exception e){
			e.printStackTrace();
		}
		if(flag==true&&flag1==true){
			
			//response.getWriter().print("{success:true,msg:'登陆成功'}");
			return SUCCESS;
		
		}else{
			//response.getWriter().print("{success:false,msg:'登陆失败'}");
			
			return ERROR;
			}
		
		}
	//用户登陆注销
	public String loginInfoOut(){
		HttpServletRequest request=ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response=ActionContextUtil.getHttpServletResponse();
		response.setCharacterEncoding("utf-8");
		request.getSession().removeAttribute("admin");
		request.getSession().removeAttribute("teachers");
		request.getSession().removeAttribute("classes");
		return SUCCESS;
	}
	
	//自动排课
	public String paike(){
		boolean flag = false;
		@SuppressWarnings("unused")
		HttpServletRequest request=ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response=ActionContextUtil.getHttpServletResponse();
		try {
			flag = recordManager.paike();
			if (flag) {
				response.getWriter().print("{success:true,msg:'排课成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'排课失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	/*
	 * 查询排课时执行插入的课程的那节课的时间段信息，如教室、老师是否已经排了课
	 */
	public String queryPaiKe(){
		String flag1 = "";
		Map map = new HashMap();
		List list = new ArrayList();
		List listreturn = new ArrayList();
		@SuppressWarnings("unused")
		HttpServletRequest request=ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response=ActionContextUtil.getHttpServletResponse();
		try {
			flag = flag.substring(0, flag.length()-1);
			String[] params= flag.split("@");
			String[] paramsHeader = params[0].split("-");
			String scheduleTitle = paramsHeader[0];
			int classId = Integer.parseInt(paramsHeader[1]);
			//map.put("classId", classId);
			map.put("scheduleTitle", scheduleTitle);
			String[] jnumber = params[1].split(",");
			for (String s:jnumber){
					String[] ss = s.split("-");
					map.put(ss[0], Integer.parseInt(ss[1]));
			}
			list.add(map);
			list.add(scheduleTitle);
			flag1 = recordManager.queryPaiKe(map);
				listreturn.add(flag1);//信息输出
			page.setRoot(listreturn);
			page.setTotalProperty(1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	/*
	 * 手动排课
	 */
	public String addPaiKe(){
		boolean flag1 = false;
		Map map = new HashMap();
		List list = new ArrayList();
		@SuppressWarnings("unused")
		HttpServletRequest request=ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response=ActionContextUtil.getHttpServletResponse();
		try {
			flag = flag.substring(0, flag.length()-1);
			String[] params= flag.split("@");
			String[] paramsHeader = params[0].split("-");
			String scheduleTitle = paramsHeader[0];
			int classId = Integer.parseInt(paramsHeader[1]);
			//map.put("classId", classId);
			map.put("scheduleTitle", scheduleTitle);
			String[] jnumber = params[1].split(",");
			for (String s:jnumber){
					String[] ss = s.split("-");
					map.put(ss[0], Integer.parseInt(ss[1]));
			}
			list.add(map);
			list.add(scheduleTitle);
			flag1 = recordManager.addPaiKe(map);
			if (flag1) {
				response.getWriter().print("{success:true,msg:'保存成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'保存失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String deletePaiKe(){
		boolean flag1 = false;
		Map map = new HashMap();
		List list = new ArrayList();
		@SuppressWarnings("unused")
		HttpServletRequest request=ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response=ActionContextUtil.getHttpServletResponse();
		try {
			flag = flag.substring(0, flag.length()-1);
			String[] params= flag.split("@");
			String[] paramsHeader = params[0].split("-");
			String scheduleTitle = paramsHeader[0];
			int classId = Integer.parseInt(paramsHeader[1]);
			//map.put("classId", classId);
			map.put("scheduleTitle", scheduleTitle);
			String[] jnumber = params[1].split(",");
			for (String s:jnumber){
					String[] ss = s.split("-");
					map.put(ss[0], Integer.parseInt(ss[1]));
			}
			list.add(map);
			list.add(scheduleTitle);
			flag1 = recordManager.deletePaiKe(map);
			if (flag1) {
				response.getWriter().print("{success:true,msg:'保存成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'保存失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	/**
	 * 查询排课计划
	 * date 2012-05-16
	 * @author xie
	 */
	public String addSchedule(){
		argsFlag = new ArgsFlag();
		boolean flag1 = false;
		String message = "";
		try{
			if("undefined".equals(flag)){
				return ERROR;
			}
			String[] params= flag.split("-");//classroomId+"-"+teacherId+"-"+classId+"-"+courseId
			argsFlag.setFlag00(Integer.parseInt(params[0]));//教室Id//班级id//老师id//课程id
			argsFlag.setFlag01(Integer.parseInt(params[2]));
			argsFlag.setFlag02(Integer.parseInt(params[1]));
			argsFlag.setFlag03(Integer.parseInt(params[3]));
			int weektimes = Integer.parseInt(params[4]);
			argsFlag.setFlag04(weektimes);
			flag1 = recordManager.addSchedule(argsFlag);
			if(flag1){
				message = "@添加成功！@";
			}else{
				message = "@添加失败！可能已有记录@";
			}
			List list = new ArrayList();
			list.add(message);
			page.setRoot(list);
		}catch(Exception e){
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}			
	
	/**
	 * 查询排课计划
	 * 
	 */
	public String querySchedule(){
		argsFlag = new ArgsFlag();
		try{
			if("undefined".equals(flag)){
				return ERROR;
			}
			if(flag!=null){
				String[] params= flag.split(",");//系院ID,专业ID,班级ID("all"),专业名,班级名,课表名,scheduleId
				if("-".equals(params[0])){
					params[0]="";
				}
				if(params.length==7){
					argsFlag.setFlag04(Integer.parseInt(params[6]));
				}
				if(!"".equals(params[2])){
					argsFlag.setFlag01(Integer.parseInt(params[2]));//班级id
				}
			}
			//argsFlag.setFlag10(params[1]);
			List<JAll> list =  recordManager.querySchedule(argsFlag);
			page.setRoot(list);
			page.setTotalProperty(10);
		}catch(Exception e){
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}			 
	
	/**
	 * 删除教学计划
	 * @return
	 */
	public String deleteSchedule() {
		try {
			boolean flag = recordManager.deleteSchedule(ids);
			@SuppressWarnings("unused")
			HttpServletRequest request = ActionContextUtil
					.getHttpServletRequest();
			HttpServletResponse response = ActionContextUtil
					.getHttpServletResponse();
			response.setCharacterEncoding("utf-8");
			if (flag) {
				response.getWriter().print("{success:true,msg:'删除成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'删除失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}

	}
	/*
	 * 通过班级查询课表
	 */
	public String queryPaikeByClassId(){
		argsFlag = new ArgsFlag();
		try{
			String[] params= flag.split(",");
			if("-".equals(params[0])){
				params[0]="";
			}
			argsFlag.setFlag01(Integer.parseInt(params[0]));//班级id
			argsFlag.setFlag10(params[1]);
			List list =  recordManager.queryPaikeByClassId(argsFlag);
			page.setRoot(list);
			page.setTotalProperty(10);
		}catch(Exception e){
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}
	
	//自动生成教学计划表
	public String scheduleJihua(){
		boolean flag = false;
		@SuppressWarnings("unused")
		HttpServletRequest request=ActionContextUtil.getHttpServletRequest();
		HttpServletResponse response=ActionContextUtil.getHttpServletResponse();
		try {
			flag = recordManager.scheduleJihua();
			if (flag) {
				response.getWriter().print("{success:true,msg:'排课成功'}");
				return null;
			} else {
				// 添加错误的提示信息
				response.getWriter().print("{success:false,msg:'排课失败'}");
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	/**
	 * @author xie
	 * 2012-05-13
	 * 通过老师查询课表
	 */
	public String queryPaikeByTeacherId(){
		argsFlag = new ArgsFlag();
		try{
			if(!"".equals(flag)){
				argsFlag.setFlag01(Integer.parseInt(flag));//教室id
				List list =  recordManager.queryPaikeByTeacherId(argsFlag);
				page.setRoot(list);
				page.setTotalProperty(10);
				}else{
					return ERROR;
				}
		}catch(Exception e){
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}
	
	/**
	 * @author xie
	 * 2012-05-13
	 * 通过教室查询课表
	 */
	public String queryPaikeByClassroomId(){
		argsFlag = new ArgsFlag();
		try{
			if(!"".equals(flag)){
			argsFlag.setFlag01(Integer.parseInt(flag));//教室id
			List list =  recordManager.queryPaikeByClassroomId(argsFlag);
			page.setRoot(list);
			page.setTotalProperty(10);
			}else{
				return ERROR;
			}
		}catch(Exception e){
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}
	
	/**
	 * @author xie
	 * date 2012-05-16
	 * 查询班级与课程的关联表
	 */
		public String queryClassRCourse(){
			argsFlag = new ArgsFlag();
			try{
				if(flag!=null){
				argsFlag.setFlag00(Integer.parseInt(flag));//班级id
				List list =  recordManager.queryCourseRClass(argsFlag);
				page.setRoot(list);
				page.setTotalProperty(10);
				}else{
					return ERROR;
				}
			}catch(Exception e){
				e.printStackTrace();
				return ERROR;
			}
			return SUCCESS;
		}
		
		/**
		 * @author xie
		 * date 2012-05-16
		 * 查询老师与课程的关联表
		 */
			public String queryTeacherRCourse(){
				argsFlag = new ArgsFlag();
				try{
					if(flag!=null){
					argsFlag.setFlag00(Integer.parseInt(flag));//课程id
					List list =  recordManager.queryTeacherRCourse(argsFlag);
					page.setRoot(list);
					page.setTotalProperty(10);
					}else{
						return ERROR;
					}
				}catch(Exception e){
					e.printStackTrace();
					return ERROR;
				}
				return SUCCESS;
			}
}
